Template Literals 與 Destructuring


Posted by cmtilo on 2021-04-30

再也不需要字串拼接:Template Literals

、、 可以放多行字串

例1

var str =、
hey
hi
、

例2

console.log(、hello, ${name.toUpperCase} now is ${new Date( )}、)

聽起來很酷的 Destructuring:解構

例1

const arr = [1, 2, 3, 4]
var [first, second, third, fourth] = arr

例2

const obj = {
 name : 'nick'
 age : 30
 address : 'taiwan'
}
var {name, age, address} = obj

例3

function test({a, b}) {
 console.log(a)
}
test({
 a : 1,
 b : 2
})

#template literals #destructuring







Related Posts

Google Chrome開發者工具教學 - Elements

Google Chrome開發者工具教學 - Elements

【JS上課筆記】JavaScript 物件導向:建構式、class、原型鏈

【JS上課筆記】JavaScript 物件導向:建構式、class、原型鏈

JAVA筆記_內部類 & 例外處理

JAVA筆記_內部類 & 例外處理


Comments